#include "message.pb.h"
#include <iostream>
#include <fstream>
 #include "message.pb.cc"

int main() {
    // 创建一个 Person 消息
    Person person;
    person.set_name("John Doe");
    person.set_id(1234);
    person.set_email("johndoe@example.com");

    // 将消息序列化到文件
    std::ofstream output("person.bin", std::ios::binary);
    if (!person.SerializeToOstream(&output)) {
        std::cerr << "Failed to write Person." << std::endl;
        return -1;
    }
    output.close();

    // 从文件中解析消息
    Person parsed_person;
    std::ifstream input("person.bin", std::ios::binary);
    if (!parsed_person.ParseFromIstream(&input)) {
        std::cerr << "Failed to parse Person." << std::endl;
        return -1;
    }
    input.close();

    // 打印解析后的消息
    std::cout << "Name: " << parsed_person.name() << std::endl;
    std::cout << "ID: " << parsed_person.id() << std::endl;
    std::cout << "Email: " << parsed_person.email() << std::endl;

    return 0;
}
